# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgbase=libnma
pkgname=(libnma-common libnma libnma-gtk4)
pkgver=1.10.6
pkgrel=2
pkgdesc="NetworkManager GUI client library"
url="https://gitlab.gnome.org/GNOME/libnma"
arch=(x86_64)
license=(GPL LGPL)
makedepends=(
  dconf
  gcr-4
  git
  gobject-introspection
  gtk-doc
  gtk3
  gtk4
  iso-codes
  libnm
  meson
  mobile-broadband-provider-info
  vala
)
_commit=3e324b69d0d74c8693fb58b9ee66efe0bad6cb34  # tags/1.10.6^0
source=(
  "git+https://gitlab.gnome.org/GNOME/libnma.git#commit=$_commit"
)
b2sums=('SKIP')

pkgver() {
  cd libnma
  git describe --tags | sed 's/-dev/dev/;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd libnma
}

build() {
  local meson_options=(
    -D libnma_gtk4=true
  )

  arch-meson libnma build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_libnma-common() {
  pkgdesc+=" (common files)"
  depends=(
    dconf
    gcr-4
    iso-codes
    libnm
    mobile-broadband-provider-info
  )

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick gtk3 usr/lib/libnma.so*
  _pick gtk3 usr/lib/pkgconfig/libnma.pc
  _pick gtk3 usr/lib/girepository-1.0/NMA-*
  _pick gtk3 usr/share/gir-1.0/NMA-*
  _pick gtk3 usr/share/vala/vapi/libnma.*

  _pick gtk4 usr/lib/libnma-gtk4.so*
  _pick gtk4 usr/lib/pkgconfig/libnma-gtk4.pc
  _pick gtk4 usr/lib/girepository-1.0/NMA4-*
  _pick gtk4 usr/share/gir-1.0/NMA4-*
  _pick gtk4 usr/share/vala/vapi/libnma-gtk4.*

  # Moved to network-manager-applet 1.30.0
  # https://bugs.archlinux.org/task/76489
  rm usr/share/glib-2.0/schemas/org.gnome.nm-applet.gschema.xml
}

package_libnma() {
  pkgdesc+=" (GTK3)"
  depends=(libnma-common="$pkgver-$pkgrel" gtk3)
  provides=(libnma.so)

  mv gtk3/* "$pkgdir"
}

package_libnma-gtk4() {
  pkgdesc+=" (GTK4)"
  depends=(libnma-common="$pkgver-$pkgrel" gtk4)
  provides=(libnma-gtk4.so)

  mv gtk4/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
